<div data-role="view" data-title="Maybanhang.Net" id="summary_day" data-layout="mobile-tabstrip-summary" data-init="initSummaryDay"
data-show="showSummaryDay">
     
        <ul data-role="listview" data-style="inset" data-type="group">        	
            <?php
            	$today = new DateTime();
				echo '<h3>Ngày '.date_format($today, 'd/m/Y').'</h3>';
            ?>   
            
            <li><label><div class="common-detail-label">Tổng hàng:</div><span id="summary_day_product_amount" class="common-detail-value">0</span></label></li>
            <li><label><div class="common-detail-label">Giảm giá:</div><span id="summary_day_reduction_amount" class="common-detail-value">0</span></label></li>
            <li><label><div class="common-detail-label">Doanh thu:</div><span id="summary_day_amount" class="common-detail-value">0</span></label></li>
            <!--<li><label><div class="common-detail-label">Lãi:</div><span id="summary_day_profit_amount" class="common-detail-value"></span></label></li>-->
            <!-- <li><label><div class="common-detail-label">Số lượng bán:</div><span id="summary_day_quantity" class="common-detail-value"></span></label></li>
             -->
            <li><label><div class="common-detail-label">Hóa đơn:</div><span id="summary_day_number_of_invoices" class="common-detail-value">0</span></label></li>
            
            <li><div class="common-detail-label">Hóa đơn mới</div>
            
            	<ul  id="list-summary-invoice-day">                
                
            	</ul>
            </li>         
         </ul>    
         <script>
	    	<?php	    		
				$today = new DateTime();			
				echo 'var today = '.date_format($today, 'Ymd').';';			
			?>
			
			function showSummaryDay()
			{
				loadSummaryDay();
			}
	    	function initSummaryDay()
	    	{	    		
	    		loadInvoiceList();
	    	}
	    	
	    	function loadSummaryDay()
	    	{
	    		app.showLoading();
	    		$.ajax({
				  type: "GET",
				  url: "service/summary?page=0&size=0&from=" + today + "&to=" +today,		 
				  dataType : 'json', 
				  async: true,
				}).done(function( data ) {
					app.hideLoading();
				    $("#summary_day_amount").html(formatAmount(data.amount));
				    $("#summary_day_product_amount").html(formatAmount(data.productAmount));
				    $("#summary_day_reduction_amount").html(formatAmount(data.reductionAmount));
				    $("#summary_day_profit_amount").html(formatAmount(data.profitAmount));
				    $("#summary_day_quantity").html(data.quantity);
				    $("#summary_day_number_of_invoices").html(data.numOfInvoice);				    
				});	
	    	}
	    	
	    	function loadInvoiceList()
	    	{
	    		pageNumber = 0;
	    		
	    		var dataSource = new kendo.data.DataSource({
	                serverPaging: true,
	                pageSize: 20,
	                transport: {
	                    read: {
	                        url: "service/invoice", 
	                        dataType: "json" 
	                    },
	                    parameterMap: function(options) {
		                    options = {	                        
		                        size: options.pageSize,
		                        from: today,
		                        to:today
		                    };
		                    if (paged) {	                        
		                         paged = false;
		                    }
		                    else
		                    {
		                    	pageNumber = 0;
		                    }
		                    options["page"] = pageNumber;
		                    return options;
		                }
	                },
	                schema: { // describe the result format
	                    parse: function(response) {
		                    pageNumber = pageNumber +1;
	                   
		                    return response;
		                },
	                    // the data which the data source will be bound to is in the "results" field
	                    data: function(data) {
	                        return data || [];
	                    },
	                    total: function() { return 10000; }
	                }
	            });
				paged = false;
		        $("#list-summary-invoice-day").kendoMobileListView({
		            dataSource: dataSource,
		            pullToRefresh: true,
		            appendOnRefresh: false,
		            endlessScroll: true,
		            endlessScrollParameters: function() {	            	
		                paged = true;
		            },
		            template: list_invoice_item_template
		        });
	    	}
	    </script>         
</div>
<div data-role="view" data-title="Maybanhang.Net" id="summary_week" data-layout="mobile-tabstrip-summary" data-init="initSummaryWeek"
data-show="showSummaryWeek">
            <ul data-role="listview" data-style="inset" data-type="group">        	
	            <?php
		            	$today = new DateTime();
						$timeFirstDayOfWeek = strtotime('monday this week');
						$dtStrFirstDayOfWeek = date("c", $timeFirstDayOfWeek);
						$dateFirstDayOfWeek = new DateTime($dtStrFirstDayOfWeek);
						echo '<h3>Tuần '.date_format($dateFirstDayOfWeek, 'd/m').' - '.date_format($today, 'd/m/Y').'</h3>';
				?>  
	            
	            <li><label><div class="common-detail-label">Tổng hàng:</div><span id="summary_week_product_amount" class="common-detail-value"></span></label></li>
	            <li><label><div class="common-detail-label">Giảm giá:</div><span id="summary_week_reduction_amount" class="common-detail-value"></span></label></li>
	            <li><label><div class="common-detail-label">Doanh thu:</div><span id="summary_week_amount" class="common-detail-value"></span></label></li>
	          <!--  <li><label><div class="common-detail-label">Lãi:</div><span id="summary_week_profit_amount" class="common-detail-value"></span></label></li>
	            <li><label><div class="common-detail-label">Số lượng bán:</div><span id="summary_week_quantity" class="common-detail-value"></span></label></li>    
            -->
	            <li><label><div class="common-detail-label">Hóa đơn:</div><span id="summary_week_number_of_invoices" class="common-detail-value"></span></label></li>
           
	         </ul>    
	         <script>
		    	<?php	
	    		$timeFirstDayOfWeek = strtotime('monday this week');
				$dtStrFirstDayOfWeek = date("c", $timeFirstDayOfWeek);
				$dateFirstDayOfWeek = new DateTime($dtStrFirstDayOfWeek);
				$today = new DateTime();
				echo 'var beginWeek = '.date_format($dateFirstDayOfWeek, 'Ymd').';';
				echo 'var today = '.date_format($today, 'Ymd').';';			
			?>
			
			function showSummaryWeek()
			{
				loadSummaryWeek();
			}
	    	function initSummaryWeek()
	    	{	    		
	    		
	    	}
	    	
	    	function loadSummaryWeek()
	    	{
	    		app.showLoading();
	    		$.ajax({
				  type: "GET",
				  url: "service/summary?page=0&size=0&from=" + beginWeek + "&to=" +today,		 
				  dataType : 'json', 
				  async: true,
				}).done(function( data ) {
					app.hideLoading();
				    $("#summary_week_amount").html(formatAmount(data.amount));
				    $("#summary_week_product_amount").html(formatAmount(data.productAmount));
				    $("#summary_week_reduction_amount").html(formatAmount(data.reductionAmount));
				    $("#summary_week_profit_amount").html(formatAmount(data.profitAmount));
				    $("#summary_week_quantity").html(data.quantity);
				    $("#summary_week_number_of_invoices").html(data.numOfInvoice);				    
				});	
	    	}
	    </script>             
</div>
<div data-role="view" data-title="Maybanhang.Net" id="summary_month" data-layout="mobile-tabstrip-summary" data-init="initSummaryMonth"
data-show="showSummaryMonth">
            <ul data-role="listview" data-style="inset" data-type="group">        	
	            <?php	            	
						$firstDayOfTheMonth = strtotime('first day of this month');
						$dtStrFirstDayOfMonth = date("c", $firstDayOfTheMonth);
						$dateFirstDayOfMonth = new DateTime($dtStrFirstDayOfMonth);
						echo '<h3>Tháng '.date_format($dateFirstDayOfMonth, 'm/Y').'</h3>';
				?>  
	            
	            <li><label><div class="common-detail-label">Tổng hàng:</div><span id="summary_month_product_amount" class="common-detail-value"></span></label></li>
	            <li><label><div class="common-detail-label">Giảm giá:</div><span id="summary_month_reduction_amount" class="common-detail-value"></span></label></li>
	            <li><label><div class="common-detail-label">Doanh thu:</div><span id="summary_month_amount" class="common-detail-value"></span></label></li>
                    <!--
	            <li><label><div class="common-detail-label">Lãi:</div><span id="summary_month_profit_amount" class="common-detail-value"></span></label></li>
	            <li><label><div class="common-detail-label">Số lượng bán:</div><span id="summary_month_quantity" class="common-detail-value"></span></label></li>
                    -->
	            <li><label><div class="common-detail-label">Hóa đơn:</div><span id="summary_month_number_of_invoices" class="common-detail-value"></span></label></li>
	         </ul>    
	         <script>
		    	<?php			
					$firstDayOfTheMonth = strtotime('first day of this month');
					//$firstDayOfTheMonth = strtotime('first day of March 2010');
					$dtStrFirstDayOfMonth = date("c", $firstDayOfTheMonth);
					$dateFirstDayOfMonth = new DateTime($dtStrFirstDayOfMonth);
					$today = new DateTime();
					echo 'var beginMonth = '.date_format($dateFirstDayOfMonth, 'Ymd').';';
					echo 'var today = '.date_format($today, 'Ymd').';';			
				?>
				
				function showSummaryMonth()
				{
					loadSummaryMonth();
				}
		    	function initSummaryMonth()
		    	{	    		
		    		
		    	}
		    	
		    	function loadSummaryMonth()
		    	{
		    		app.showLoading();
		    		$.ajax({
					  type: "GET",
					  url: "service/summary?page=0&size=0&from=" + beginMonth + "&to=" +today,		 
					  dataType : 'json', 
					  async: true,
					}).done(function( data ) {
						app.hideLoading();
					    $("#summary_month_amount").html(formatAmount(data.amount));
					    $("#summary_month_product_amount").html(formatAmount(data.productAmount));
					    $("#summary_month_reduction_amount").html(formatAmount(data.reductionAmount));
					    $("#summary_month_profit_amount").html(formatAmount(data.profitAmount));
					    $("#summary_month_quantity").html(data.quantity);
					    $("#summary_month_number_of_invoices").html(data.numOfInvoice);				    
					});	
		    	}
		    </script>            
</div>
<div data-role="layout" data-id="mobile-tabstrip-summary" >
	<header data-role="header">
        <div data-role="navbar">
            <a id="back-button" class="nav-button" data-align="left" data-role="backbutton" href='#index'>Back</a>
            <!--<span data-role="view-title"></span>-->
            <span ><?php echo UserInformation::getLocationName(); ?></span>
            <a data-align="right" data-role="button" class="nav-button" href='#index'>Home</a>            
        </div>
    </header>   
    <div data-role="footer">
        <div data-role="tabstrip">
            <a href="#summary_day" data-icon="recents">Ngày
            </a><a href="#summary_week" data-icon="mostrecent">Tuần
            </a><a href="#summary_month" data-icon="organize">Tháng            
        </div>
    </div>
</div>
